package icu.xlg

import spock.lang.Specification
import spock.lang.Title

@Title("电视机Spec")
class TelevisionSpecification extends Specification {

    def '电视机的开机后会播放广告'() {
        given: "初始化"
        Ad ad = Mock(Ad)
        Television tv = new Television(Status.OFF, ad)
        when: "开机"
        boolean turnedOn = tv.turnOn()
        then: "开机成功，且播放广告"
        turnedOn == true
        1 * ad.show()
    }

    def '电视机可以关机'() {
        given: "初始化电源"
        Power power = Mock(Power)
        Television tv = new Television(power)
        when: "关机"
        boolean turnedOff = tv.turnOff()
        then: "关机成功"
        turnedOff == true
    }

    def '电视机在开机状态下休眠'() {
        given: "初始化"
        Television tv = new Television(Status.ON)
        when: "休眠"
        boolean hibernated = tv.hibernate()
        then: "休眠成功"
        hibernated == true
    }

    def '电视机在休眠状态可以唤醒成功并播放广告'() {
        given: "初始化"
        Ad ad = Mock(Ad)
        Television tv = new Television(Status.HIBERNATED, ad)
        when: "唤醒"
        boolean on = tv.wakeUp()
        then: "唤醒成功"
        on == true
        1 * ad.show()
    }
}